package com.liu.controller;

import com.liu.domain.VoteCount;
import com.liu.domain.VoteTopic;
import com.liu.domain.student;
import com.liu.repository.VotecountRepository;
import com.liu.repository.VotetopicRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;

/**
 * Created by liu on 17-9-21.
 */
@Controller
public class indexController {

    @Autowired
    private VotetopicRepository votetopicRepository;

    @Autowired
    private VotecountRepository VotecountRepository;

    @RequestMapping("/we")
    public String index() {
        return "indexq";
    }     //系统管理员主页面

    @RequestMapping("/student")                  //学生主页面
    public String stu() {
        return  "student/Stuindex";
    }

    @RequestMapping("/studemo")
    public String stuDemo() {
        return "StudentSelect";
    }   //学生模块

    @GetMapping("/dmdemo")
    public String dm(){
        return "DmSelect";
    }  //宿管模块

    @RequestMapping("/login")
    public String login() {
        return  "login";
    }     //登录

    @RequestMapping("/textdemo")
    public String text() {
        return  "text";
    }       //管理员公告

    @RequestMapping("/stuText")
    public String stuText() {
        return  "student/stuText";
    }       //学生公告
    @RequestMapping("/Addtextdemo")                  //添加公告
    public String Addtext() {
        return  "Addtext";
    }

    @RequestMapping("/ruledemo")                  //违规
    public String rule() {
        return  "rule";
    }

    @RequestMapping("/pddemo")                  //基本资料
    public String pd() {
        return  "Personaldata";
    }

    @RequestMapping("/cpdemo")                  //安全设置
    public String cp() {
        return  "Changeps";
    }

    @RequestMapping("/indexdemo")                  //默认主页
    public String index1() {
        return  "index";
    }

    @RequestMapping("/vote")                  //打投票主页
    public String vote() {

        return  "student/Votemain";
    }
    @RequestMapping("/addvote")                  //添加投票主题
    public String addvote(Model model) {
        Date date = new Date();
        List<VoteTopic> list = votetopicRepository.isOut(date);
        boolean ok = false;
        if (list != null && list.size()>0) {
            ok = true;
        }
        model.addAttribute("isOut", ok);
        return  "addVote";
    }

    @RequestMapping("/stuVote")                  //学生上传投票资料
    public String stuVote(HttpSession session, Model model) {
        student s = (student) session.getAttribute("user");
        int roomId = s.getRoom_id();
        int count = VotecountRepository.findbyroom(roomId);
        boolean ok = false;
         if (count > 0){
             ok = true;
         }
         model.addAttribute("you",ok);
        return  "student/stuVote";
    }

    @GetMapping("/isStart")
    @ResponseBody
    public boolean isStart() {
        boolean ok = false;
        Date date = new Date();
        List<VoteTopic> topics = votetopicRepository.isStart(date);
        if (topics != null && topics.size()>0) {
            ok = true;
        }
        return ok;
    }

    @RequestMapping("/addstudent")                  //学生上传投票资料
    public String adds() {
        return  "addStudent";
    }

    @RequestMapping("/relativeStu")
    public String relativeStu() {
        return "relativestudent";
    }

    @RequestMapping("/roomStu")
    public String roomstu() {
        return "student/roomStu";
    } //本寝学生

    @RequestMapping("/claStu")
    public String clastu() {
        return "student/claStu";
    }   //本班学生

    @RequestMapping("/stuChange")
    public String stuchange() {
        return "student/stuChange";
    }   //学生用户改密码

    @RequestMapping("/teaSelect")
    public String teaSelect() {
        return "teaSelect";
    }      //管理员管理

    @RequestMapping("/addStu")
    public String addStu() {
        return "addStu";
    }    //添加一名学生

    @RequestMapping("/addTea")
    public String addTea() {
        return "addTea";
    }    //添加一名老师

    @RequestMapping("/voteLook")
    public String votelook() {
        return "voteLook";
    }  //投票情况

    @RequestMapping("/heaSelect")
    public String heaSelect() {
        return "heaSelect";      //投票情况
    }

    @RequestMapping("/xtindex")
    public String xtindex() {
        return "xitong/xtindex";
    }//系统管理员

    @RequestMapping("/addRule")
    public String addRule() {
        return "addRule";
    }//添加违规

    @RequestMapping("/addHea")
    public String addHea() {
        return "addHea";
    }

    @RequestMapping("/tiaozhuan")
    public String tiao() {
        return "tiaozhuan";
    }

    @RequestMapping("/xtChange")
    public String xtC() {
        return "xitong/xtChange";
    }
    @RequestMapping("/xtPerson")
    public String xtP() {
        return "xitong/xtPerson";
    }

    @RequestMapping("/sIndex")
    public String si() {
        return "student/sIndex";   //学生主页面
    }
    @RequestMapping("/jifen")
    public String jifen() {
        return "jifen";
    }         //积分

    @RequestMapping("/xtStudent")
    public String xtStudent() {
        return "xitong/xtStudent";
    }

    @RequestMapping("/xtHea")
    public String xtHea() {
        return "xitong/xtHea";
    }

    @RequestMapping("/xtRule")
    public String xtRule() {
        return "xitong/xtRule";
    }

    @RequestMapping("/xtJF")
    public String xtJF() {
        return "xitong/xtJF";
    }

    @RequestMapping("/stuJfpm")
    public String stuJfpm() {
        return "student/stuJfpm";
    }




}
